const { User } = require('../../model/user');

module.exports = async (req, res) => {
    req.app.locals.current = 'user';

    let { page, limit } = req.query;
    // page 页数
    page = parseInt(page) || 1;
     // limit 每一页显示的数据条数
    limit = parseInt(limit) || 10;
    // 数据总数
    let count = await User.countDocuments({});
    // 总页数
    let total = Math.ceil(count / limit);
    // 页码对应的数据查询开始位置
    let start = (page - 1) * limit;

    // console.log(page+" "+limit+" "+count+" "+total+" "+start);

    let users = await User.find({}).limit(limit).skip(start);
    res.render('admin/user', {
        users,
        page,
        limit,
        total
    });
}